//获取应用实例
var app = getApp()
Page({
  data: {
   
  },
  onLoad: function (e) {
    var that = this;
    if (e && e.enterfrom) {
      var enterfrom = e.enterfrom == 'share' ? true : false;
      that.setData({
        enterfrom: enterfrom
      })
    }
    that.requestApplet();
  },
  onShow: function () {
    app.setNavtitle('导航');
    app.setCartnum();//更新购物车数量
  },
  requestApplet: function () {
    var that = this;
    //发起请求，获取列表列表
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      mask: true,
      duration: 10000
    });
    wx.request({
      url: app.globalData.requestUrl,
      data: {
        map: 'applet_applet_jump_list'
      },
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          console.log(res.data.data)
          that.setData({
            appletInfo: res.data.data
          })
          
        } else {
          console.log(res.data)
          that.setData({
            appletInfo: ""
          })
          // app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.hideToast();
        wx.stopPullDownRefresh();
      }
    });
  },
  onPullDownRefresh:function(){
    this.requestApplet();
  },
  openApplet: function (e) {
    var path = e.currentTarget.dataset.path;
    var appid = e.currentTarget.dataset.appid;
    console.log(path);
    console.log(appid);
    wx.navigateToMiniProgram({
      appId: appid,
      path: path,
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
  onShareAppMessage: function () {
    var that = this;
    var shareInfo = app.globalData.shareInfo;
    var title = shareInfo.shareTitle ? shareInfo.shareTitle : '';
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/pages/appletList/appletList?enterfrom=share'
    }
  }
})
